package com.lxmes.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.business.domain.NcJiesuanRules;
import com.lxmes.business.service.INcJiesuanRulesService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 结算规则Controller
 *
 * @author zhangzhiyu
 * @date 2022-11-29
 */
@RestController
@RequestMapping("/business/jsRules")
public class NcJiesuanRulesController extends BaseController
{
    @Autowired
    private INcJiesuanRulesService ncJiesuanRulesService;

    /**
     * 查询结算规则列表
     */
    @PreAuthorize("@ss.hasPermi('business:jsRules:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcJiesuanRules ncJiesuanRules)
    {
        startPage();
        List<NcJiesuanRules> list = ncJiesuanRulesService.selectNcJiesuanRulesList(ncJiesuanRules);
        return getDataTable(list);
    }

    /**
     * 导出结算规则列表
     */
    @PreAuthorize("@ss.hasPermi('business:jsRules:export')")
    @Log(title = "结算规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcJiesuanRules ncJiesuanRules)
    {
        List<NcJiesuanRules> list = ncJiesuanRulesService.selectNcJiesuanRulesList(ncJiesuanRules);
        ExcelUtil<NcJiesuanRules> util = new ExcelUtil<NcJiesuanRules>(NcJiesuanRules.class);
        util.exportExcel(response, list, "结算规则数据");
    }

    /**
     * 获取结算规则详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:jsRules:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncJiesuanRulesService.selectNcJiesuanRulesById(id));
    }

    /**
     * 新增结算规则
     */
    @PreAuthorize("@ss.hasPermi('business:jsRules:add')")
    @Log(title = "结算规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcJiesuanRules ncJiesuanRules)
    {
        return toAjax(ncJiesuanRulesService.insertNcJiesuanRules(ncJiesuanRules));
    }

    /**
     * 修改结算规则
     */
    @PreAuthorize("@ss.hasPermi('business:jsRules:edit')")
    @Log(title = "结算规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcJiesuanRules ncJiesuanRules)
    {
        return toAjax(ncJiesuanRulesService.updateNcJiesuanRules(ncJiesuanRules));
    }

    /**
     * 删除结算规则
     */
    @PreAuthorize("@ss.hasPermi('business:jsRules:remove')")
    @Log(title = "结算规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncJiesuanRulesService.deleteNcJiesuanRulesByIds(ids));
    }
}
